package com.zhang.common.enums;

import java.util.Objects;

/**采购单状态
 * @author hongmizfb
 * @date 2024/07/04
 */
public enum PurchaseStatusEnum {
    //    状态列表
    NEW_CREATE(0, "新建"),
    ASSIGNED(1, "已分配"),
    CLAIMED(2, "已领取"),
    FINISHED(3, "已完成"),
    ABNORMAL(4, "异常"),
    ;
    private final Integer status;
    private final String description;

    PurchaseStatusEnum(Integer status, String description) {
        this.status = status;
        this.description = description;
    }

    public static PurchaseStatusEnum getByStatus(Integer status) {
        //        遍历枚举寻找满足的状态
        for (PurchaseStatusEnum purchaseStatusEnum : PurchaseStatusEnum.values()) {
            if (Objects.equals(purchaseStatusEnum.getStatus(), status)) {
                return purchaseStatusEnum;
            }
        }
        throw new IllegalArgumentException("Unknown status : " + status);
    }

    public static PurchaseStatusEnum getByDescription(String description) {
//        遍历枚举寻找满足的状态
        for (PurchaseStatusEnum purchaseStatusEnum : PurchaseStatusEnum.values()) {
            if (purchaseStatusEnum.getDescription().equals(description)) {
                return purchaseStatusEnum;
            }
        }
        throw new IllegalArgumentException("Unknown description : " + description);
    }

    public Integer getStatus() {
        return status;
    }

    public String getDescription() {
        return description;
    }

}
